#include "StdAfx.h"
#include "LogUtil.h"
#include "Utils.h"

using namespace std;

ofstream CLogUtil::m_callOutLog;
ofstream CLogUtil::m_runningLog;
ofstream CLogUtil::m_netMessageLog;
ofstream CLogUtil::m_sipStatusLog;
ofstream CLogUtil::m_importErrorLog;
ofstream CLogUtil::m_test1Log;
ofstream CLogUtil::m_test2Log;

CLogUtil::CLogUtil(void)
{
}

CLogUtil::~CLogUtil(void)
{
	if (m_callOutLog.is_open())
	{
		m_callOutLog.close();
	}	
	if (m_runningLog.is_open())
	{
		m_runningLog.close();
	}
	if (m_netMessageLog.is_open())
	{
		m_netMessageLog.close();
	}
	if (m_sipStatusLog.is_open())
	{
		m_sipStatusLog.close();
	}
	if (m_importErrorLog.is_open())
	{
		m_importErrorLog.close();
	}
	if (m_test1Log.is_open())
	{
		m_test1Log.close();
	}
	if (m_test2Log.is_open())
	{
		m_test2Log.close();
	}
}

void CLogUtil::checkLogPath()
{
	CUtils::checkDirExistAndCreate("./log/");
}

void CLogUtil::writeRunningInfoLog(const char* logInfo)
{
	if (!m_runningLog.is_open())
	{
		m_runningLog.open("./log/running_info.log", ios::trunc);
	}
	if (logInfo == nullptr)
	{
		return;
	}

	char sztm[50] = {0};
	CUtils::getCurrentDayTime(sztm);
	m_runningLog << sztm << " " << logInfo << endl;
}

void CLogUtil::writeCallInfoLog(const char* logInfo)
{
	if (!m_callOutLog.is_open())
	{
		m_callOutLog.open("./log/dial_call_phone.log", ios::trunc);
	}
	if (logInfo == nullptr)
	{
		return;
	}

	char sztm[50] = {0};
	CUtils::getCurrentDayTime(sztm);
	m_callOutLog << sztm << " " << logInfo << endl;
}

void CLogUtil::writeNetMessageLog(char* logInfo)
{
	if (!m_netMessageLog.is_open())
	{
		m_netMessageLog.open("./log/net_message.log", ios::trunc);
	}
	if (logInfo == nullptr)
	{
		return;
	}

	char sztm[50] = {0};
	CUtils::getCurrentDayTime(sztm);
	if (strlen(logInfo) > 200)
	{
		logInfo[200] = '\0';
	}
	m_netMessageLog << sztm << " " << logInfo << endl;
}

void CLogUtil::writeSipStatusLog(const char* logInfo)
{
	if (!m_sipStatusLog.is_open())
	{
		m_sipStatusLog.open("./log/sip_status.log", ios::trunc);
	}
	if (logInfo == nullptr)
	{
		return;
	}

	char sztm[50] = {0};
	CUtils::getCurrentDayTime(sztm);
	m_sipStatusLog << sztm << " " << logInfo << endl;
}

void CLogUtil::writeImportClientExcelErrorLog(const char* logInfo)
{
	if (!m_importErrorLog.is_open())
	{
		m_importErrorLog.open("./log/import_error.log", ios::trunc);
	}
	if (logInfo == nullptr)
	{
		return;
	}

	char sztm[50] = {0};
	CUtils::getCurrentDayTime(sztm);
	m_importErrorLog << sztm << " " << logInfo << endl;
}

void CLogUtil::writeTest1Log(const char* logInfo)
{
	if (!m_test1Log.is_open())
	{
		m_test1Log.open("./log/test1.log", ios::app);
	}
	if (logInfo == nullptr)
	{
		return;
	}

	char sztm[50] = {0};
	CUtils::getCurrentDayTime(sztm);
	m_test1Log << sztm << " " << logInfo << endl;
}

void CLogUtil::writeTest2Log(const char* logInfo)
{
	if (!m_test2Log.is_open())
	{
		m_test2Log.open("./log/test2.log", ios::app);
	}
	if (logInfo == nullptr)
	{
		return;
	}

	char sztm[50] = {0};
	CUtils::getCurrentDayTime(sztm);
	m_test2Log << sztm << " " << logInfo << endl;
}


